import { MockMethod } from 'vite-plugin-mock'
import pkg from 'mockjs'
const { Random } = pkg

// 模型列表数据
const modelList = [
  {
    id: '1',
    name: 'GPT-3.5',
    icon: 'https://via.placeholder.com/32',
    host: 'https://api.openai.com/v1/chat/completions',
    manageHost: 'https://platform.openai.com',
    status: 'Healthy',
    lastHeartBeat: '2023-10-18 12:30:45',
    createdAt: '2023-10-01',
    updatedAt: '2023-10-01'
  },
  {
    id: '2',
    name: 'GPT-4',
    icon: 'https://via.placeholder.com/32',
    host: 'https://api.openai.com/v1/chat/completions',
    manageHost: 'https://platform.openai.com',
    status: 'Healthy',
    lastHeartBeat: '2023-10-18 12:35:22',
    createdAt: '2023-10-02',
    updatedAt: '2023-10-02'
  },
  {
    id: '3',
    name: 'Claude-2',
    icon: 'https://via.placeholder.com/32',
    host: 'https://api.anthropic.com/v1/messages',
    manageHost: 'https://console.anthropic.com',
    status: 'llm',
    lastHeartBeat: '2023-10-18 12:28:11',
    createdAt: '2023-10-03',
    updatedAt: '2023-10-03'
  },
  {
    id: '4',
    name: 'Embedding-Model',
    icon: 'https://via.placeholder.com/32',
    host: 'https://api.embedding.com/v1',
    manageHost: 'https://console.embedding.com',
    status: 'text2vec',
    lastHeartBeat: '2023-10-18 12:40:33',
    createdAt: '2023-10-04',
    updatedAt: '2023-10-04'
  }
]

export default [
  // 获取模型列表
  {
    url: '/api/model/list',
    method: 'get',
    response: () => {
      return {
        code: 0,
        data: modelList,
        message: '获取成功'
      }
    }
  },
  
  // 获取模型详情
  {
    url: '/api/model/:id',
    method: 'get',
    response: (request) => {
      const { id } = request.params
      const model = modelList.find(item => item.id === id)
      
      if (model) {
        return {
          code: 0,
          data: model,
          message: '获取成功'
        }
      } else {
        return {
          code: 1,
          data: null,
          message: '模型不存在'
        }
      }
    }
  },
  
  // 创建模型
  {
    url: '/api/model/create',
    method: 'post',
    response: (request) => {
      const model = request.body
      const newModel = {
        id: Random.id(),
        ...model,
        createdAt: new Date().toISOString().split('T')[0],
        updatedAt: new Date().toISOString().split('T')[0],
        lastHeartBeat: new Date().toLocaleString()
      }
      
      modelList.unshift(newModel)
      
      return {
        code: 0,
        data: newModel,
        message: '创建成功'
      }
    }
  },
  
  // 更新模型
  {
    url: '/api/model/:id',
    method: 'put',
    response: (request) => {
      const { id } = request.params
      const updateData = request.body
      
      const index = modelList.findIndex(item => item.id === id)
      if (index !== -1) {
        modelList[index] = {
          ...modelList[index],
          ...updateData,
          updatedAt: new Date().toISOString().split('T')[0]
        }
        
        return {
          code: 0,
          data: modelList[index],
          message: '更新成功'
        }
      } else {
        return {
          code: 1,
          data: null,
          message: '模型不存在'
        }
      }
    }
  },
  
  // 删除模型
  {
    url: '/api/model/:id',
    method: 'delete',
    response: (request) => {
      const { id } = request.params
      
      const index = modelList.findIndex(item => item.id === id)
      if (index !== -1) {
        modelList.splice(index, 1)
        
        return {
          code: 0,
          data: null,
          message: '删除成功'
        }
      } else {
        return {
          code: 1,
          data: null,
          message: '模型不存在'
        }
      }
    }
  }
] as MockMethod[] 